#include <iostream>
#include <cstdlib>
#include "compare.h"
using namespace std;

void Compare::do_all(){
	for(int i=0; i<(int)A->getFromfile().size()-1; i+=2){
		bool is_true = true;
		for(int j=0; j<(int)A->getTofile().size()-1; j+=2){
			if(A->getFromfile()[i]==A->getTofile()[j]) {
				if(A->getFromfile()[i+1]==A->getTofile()[j+1]) is_true=false;
			}
		}

		if(is_true){
			compared_files.push_back(A->getFromfile()[i]);
			int pomsize = compared_files.size();
			if(shieldcheck() && shield[1]!=""){
				if(A->getSize()[i/2]>(atof(shield[1].c_str()))) compared_files.pop_back();
			}
			bool oinside=true, ooutside=false, einside=false, eoutside=false;
			if(shieldcheck() && shield[2]!="" && pomsize==(int)compared_files.size()){
				for(int k=1; k<(int)shield2split.size(); k+=2){
					if(shield2split[k]=="onl"){
						oinside=extension(k-1);
					}
					else{
						einside=extension(k-1);
					}
					if(oinside) ooutside=true;
					if(einside) eoutside=true;
				}
				if(!ooutside) compared_files.pop_back();
				if(eoutside) compared_files.pop_back();
			}
		}
	}
}

bool Compare::extension(int i){
	bool inside=true;
	for(int h=1; h<=(int)shield2split[i].size(); h++){
		if(compared_files.back()[compared_files.back().size()-h]!=shield2split[i][shield2split[i].size()-h])
			{inside=false; break;}
			else inside = true;
	}
	return inside;
}

bool Compare::shieldcheck(){
	if(shield[0]=="off") return false;
	else return true;
}


